from typing import Optional
from pydantic import BaseModel, Field
from datetime import datetime
from .base import BaseSchema
from .user import UserSchema
from .drone_type import DroneTypeSchema
from .department import DepartmentSchema

class DroneBase(BaseSchema):
    """无人机基础模型"""
    name: str = Field(..., max_length=100, description="无人机名称")
    serial_number: str = Field(..., max_length=100, description="序列号")
    drone_type_id: int = Field(..., description="无人机类型ID")
    operator_id: Optional[int] = Field(None, description="操作员ID")
    department_id: Optional[int] = Field(None, description="所属部门ID")
    status: Optional[str] = Field("available", description="状态")
    latitude: Optional[float] = Field(None, description="当前纬度")
    longitude: Optional[float] = Field(None, description="当前经度")
    altitude: Optional[float] = Field(None, description="当前高度")
    battery_level: Optional[int] = Field(None, description="电池电量")
    maintenance_date: Optional[datetime] = Field(None, description="下次维护日期")

class DroneCreate(DroneBase):
    """创建无人机模型"""
    pass

class DroneUpdate(DroneBase):
    """更新无人机模型"""
    pass

class DroneSchema(DroneBase):
    """无人机响应模型"""
    last_flight_time: Optional[datetime] = Field(None, description="最后飞行时间")
    total_flight_time: Optional[int] = Field(None, description="总飞行时间")
    operator: Optional[UserSchema] = Field(None, description="操作员信息")
    drone_type: Optional[DroneTypeSchema] = Field(None, description="无人机类型信息")
    department: Optional[DepartmentSchema] = Field(None, description="部门信息")